import api from "./request.js"
import md5 from "js-md5"
//注册接口
export const register=(username,pwd)=>api.post('/user/register', {loginName: username,password: pwd})
//登录接口
export const login=(username,pwd)=>api.post('/user/login', {loginName: username,passwordMd5: md5(pwd)})
//首页面接口
export const gethome =()=>api.get("/index-infos")
//详情页接口
export const getinfodata =(id)=>api.get("/goods/detail/"+id)
//点击加入购物车
export const addcart =(goodsCount,goodsId)=>api.post("/shop-cart",{goodsCount,goodsId})
//获取购物车数据
export const getcartlist =()=>api.get("/shop-cart")
//点击删除
export const delcartlist =(id)=>api.delete("/shop-cart/"+id)
//增加商品数量
export const putcartnum =(cartItemId,goodsCount)=>api.put("/shop-cart",{cartItemId,goodsCount})
//获取地址列表
export const getAddressList=() => api.get("/address")

//根据ID获取某个地址，实现数据回显
export const getAddressDetail=(id)=> api.get("/address/" + id)

//编辑地址
export const updateAddress=(obj) => api.put("/address", obj)

//新增地址
export const addAddress=(obj)=> api.post("/address", obj)

//删除地址
export const removeAddress=(id)=> api.delete("/address/" + id)

//根据id获取订单购的商品数据  /shop-cart/settle?cartItemIds=55088
export const getordercart=(ids)=> api.get("/shop-cart/settle?cartItemIds="+ids)

//生成订单接口
export const createorder=(addressId, cartItemIds)=> api.post("/saveOrder",{addressId, cartItemIds})

//支付接口  /paySuccess?orderNo=16722345127784241&payType=1
// export const paysuccess=(orderNo, payType)=> api.get(`/paySuccess?orderNo=${orderNo}&payType=${payType}`)
export const paysuccess=(orderNo, payType)=> api.get("/paySuccess",{
    params:{
        orderNo,
        payType
    }
})

//获取订单数 /order?pageNumber=1&status=
export const getmyorder=(pageNumber, status)=> api.get("/order",{
    params:{
        pageNumber,
        status
    }
})

//获取订单详情 /order/16722822067935286
export const getorderdetail=(id)=> api.get("/order/"+id)

//确认收货
export const finish=(id)=>api.put(`/order/${id}/finish`)
//取消订单 /order/16722365266903564/cancel
export const cancel=(id)=>api.put(`/order/${id}/cancel`)

//获取用户信息 /user/info
export const getuser=()=>api.get('/user/info')
//修改用户信息
export const putuserinfo=(introduceSign,nickName,passwordMd5)=>api.put('/user/info',{introduceSign,nickName,passwordMd5})
